<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  

  
  <title>python集训 _人脸识别 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="最近集训了为期四天的python培训，主要是学习人脸识别。   首先说一下遇到的问题汇总，1.python的环境配置 2.python的pip安装 3.pycharm的使用关于python的环境配置，目前有很多种版本的python。如3.7.0，3.8.0，我之前安装的是3.8的python，所以有很多老师提供3.7版本pip我安装不上，pypi上也没有对应的3.8版本。所以我卸载了原先的3">
<meta name="keywords" content="python">
<meta property="og:type" content="article">
<meta property="og:title" content="python集训 _人脸识别">
<meta property="og:url" content="http://yoursite.com/2019/12/26/python集训-人脸识别/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="最近集训了为期四天的python培训，主要是学习人脸识别。   首先说一下遇到的问题汇总，1.python的环境配置 2.python的pip安装 3.pycharm的使用关于python的环境配置，目前有很多种版本的python。如3.7.0，3.8.0，我之前安装的是3.8的python，所以有很多老师提供3.7版本pip我安装不上，pypi上也没有对应的3.8版本。所以我卸载了原先的3">
<meta property="og:locale" content="en">
<meta property="og:image" content="http://yoursite.com/2019/12/26/python集训-人脸识别/%E9%80%89%E6%8B%A9python%E7%8E%AF%E5%A2%83.png">
<meta property="og:updated_time" content="2019-12-26T13:01:51.514Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="python集训 _人脸识别">
<meta name="twitter:description" content="最近集训了为期四天的python培训，主要是学习人脸识别。   首先说一下遇到的问题汇总，1.python的环境配置 2.python的pip安装 3.pycharm的使用关于python的环境配置，目前有很多种版本的python。如3.7.0，3.8.0，我之前安装的是3.8的python，所以有很多老师提供3.7版本pip我安装不上，pypi上也没有对应的3.8版本。所以我卸载了原先的3">
<meta name="twitter:image" content="http://yoursite.com/2019/12/26/python集训-人脸识别/%E9%80%89%E6%8B%A9python%E7%8E%AF%E5%A2%83.png">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-python集训-人脸识别" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2019/12/26/python集训-人脸识别/" class="article-date">
  <time datetime="2019-12-26T12:49:11.000Z" itemprop="datePublished">2019-12-26</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      python集训 _人脸识别
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>   最近集训了为期四天的python培训，主要是学习人脸识别。<br>   首先说一下遇到的问题汇总，1.python的环境配置 2.python的pip安装 3.pycharm的使用<br>关于python的环境配置，目前有很多种版本的python。如3.7.0，3.8.0，我之前安装的是3.8的python，所以有很多老师提供3.7版本pip我安装不上，pypi上也没有对应的3.8版本。所以我卸载了原先的3.8安装了3.7(最简单的卸载方法就是找到python的源文件双击uninstall，找不到就更新一个更高的版本安装后再卸载)。要记好python的安装路径。<br>然后是pip的安装，首先要确定你所需要的pip是否能和你的python版本对应的上，不对应可以去pypi的官网或者国内的镜像网站清华源找。找到之后下载到任意路径，然后打开下载到的文件夹，在上方输入cmd。输入pip install +文件名字(打出几个字母后按tab键)。输入pip list可以查看你所安装的全部pip，输入pip uninstall+文件名 可以卸载对应pip。<br>pycharm的使用，这才是重点。原来以前我写的那些代码都是用虚拟环境运行的，难怪import pygame一直失败。使用pycharm时如果不使用已安装的python环境他会给你创建一个虚拟环境，虚拟环境的优点是体积小，随项目移动。但是你安装的pip他是不会自动识别的，需要手动的添加进去。操作步骤为：文件-设置-项目-project Interpreter-右方的+号(-号就是删除)-然后搜索pip。<img src="/2019/12/26/python集训-人脸识别/%E9%80%89%E6%8B%A9python%E7%8E%AF%E5%A2%83.png" alt><br>    这次实训主要是对cv2的一些操作讲解以及认识到图片，声音，视频的数字化。图片就是一个三维的。可以使用print(cv2. imread(‘./文件名.’))查看文件是一个几维的。对图片来说，一二维确定图片的长宽，三维确定颜色(红绿蓝，全255为白，全0为黑)。贴一个代码 将人物的眼睛替换为心。</p>
<figure class="highlight nix"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">import</span> cv2  <span class="comment"># 导入cv2包</span></span><br><span class="line"></span><br><span class="line"><span class="attr">face</span> = cv2.imread('./face1.jpg')  <span class="comment"># 将face1读取并赋给face</span></span><br><span class="line"><span class="attr">eye_detector</span> = cv2.CascadeClassifier('./haarcascade_eye.xml.')  <span class="comment"># 使用方法CascadeClassifier定义一个眼睛探测器</span></span><br><span class="line"><span class="attr">eye_zones</span> = eye_detector.detectMultiScale(face, <span class="attr">scaleFactor=1.08,</span> <span class="attr">minNeighbors=50)</span>  <span class="comment"># 使用眼睛探测器定位出face中的眼睛位置</span></span><br><span class="line">for x, y, w, h <span class="keyword">in</span> eye_zones:</span><br><span class="line">    <span class="attr">heart</span> = cv2.imread('./heart.jpg')  <span class="comment"># 读取heart图片赋值给变量heart</span></span><br><span class="line">    <span class="attr">heart</span> = cv2.resize(heart, <span class="attr">dsize=(w,</span> h))  <span class="comment"># 重新定义heart的大小</span></span><br><span class="line">    for i <span class="keyword">in</span> range(w):</span><br><span class="line">        for j <span class="keyword">in</span> range(h):</span><br><span class="line">            <span class="keyword">if</span> (heart[i, j][<span class="number">0</span>] &lt; <span class="number">10</span>) &amp; (heart[i, j][<span class="number">1</span>] &lt; <span class="number">10</span>) &amp; (heart[i, j][<span class="number">2</span>] &lt; <span class="number">10</span>):  <span class="comment"># 检测图片的颜色，黑色则pass</span></span><br><span class="line">                pass</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                face[y + i, x + j] = heart[i, j]  <span class="comment"># 未被检测为黑色的部分被赋给face的眼睛部分</span></span><br><span class="line">cv2.imshow('face', face)  <span class="comment"># 弹出一个窗口显示修改后的图片</span></span><br><span class="line">cv2.waitKey(<span class="number">0</span>)  <span class="comment"># 等待键盘输入，0为无限等待</span></span><br><span class="line">cv2.destroyAllWindows()  <span class="comment"># 释放内存</span></span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2019/12/26/python集训-人脸识别/" data-id="ck4mql4da0004tsudvkkv1a7u" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/">python</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
  
    <a href="/2019/09/29/学生信息课题实现及源代码/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">学生信息课题实现及源代码</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/C-C/">C/C++</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo使用帮助/">hexo使用帮助</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/">python</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/C-C/" style="font-size: 10px;">C/C++</a> <a href="/tags/hexo使用帮助/" style="font-size: 20px;">hexo使用帮助</a> <a href="/tags/java/" style="font-size: 10px;">java</a> <a href="/tags/python/" style="font-size: 10px;">python</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">December 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">September 2019</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2019/12/26/python集训-人脸识别/">python集训 _人脸识别</a>
          </li>
        
          <li>
            <a href="/2019/09/29/学生信息课题实现及源代码/">学生信息课题实现及源代码</a>
          </li>
        
          <li>
            <a href="/2019/09/18/hexo + github 博客图片插入/">hexo + github 博客图片插入</a>
          </li>
        
          <li>
            <a href="/2019/09/17/JDK环境变量配置/">JDK环境变量配置</a>
          </li>
        
          <li>
            <a href="/2019/09/11/hello-world/">Hello World</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2019 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>